﻿<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="ProcessUpgrade.aspx.cs" Inherits="Cms.Web.UI.Admin.ProcessUpgrade" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <link rel="stylesheet" type="text/css" href="Admin/Css/Main.css" />
    <link rel="stylesheet" type="text/css" href="Admin/Css/MainBox.css" />
    <link rel="stylesheet" type="text/css" href="Admin/Css/Public.css" />
    <link rel="stylesheet" type="text/css" href="Admin/Css/Buttons.css" />
    <link rel="stylesheet" type="text/css" href="Admin/Css/Dialogs.css" />
    <link rel="stylesheet" type="text/css" href="Admin/Css/PopupMenu.css" />
    <script language="javascript" type="text/javascript" src="Admin/Js/CmsLib.js"></script>
    <script language="javascript" type="text/javascript" src="Admin/Js/Dialogs.js"></script>
    <script language="javascript" type="text/javascript" src="Admin/Js/Lists.js"></script>
    <script language="javascript" type="text/javascript">
        //<![CDATA[

        var baseHref;
        var interval;
        var applicationRestarted;
        var steps = new Array("RemoveHttpModules",
                              "ApplyConfigPatches",
                              "UnzipUpdatePackage",
                              "Compiling",
                              "ApplyDatabasePatches",
                              "RestoreHttpModules");
        var currentStep = -1;

        function startUpgrade(domain) {
            baseHref = domain;
            executeNextStep();
            if (document.getElementById("hidManualRestarts").value == "true") {
                window.setTimeout(function() { document.getElementById("hlManualContinue").style.visibility = "visible"; }, 5000);
            }
        }

        function executeNextStep() {
            currentStep++;
            hideSpans();
            document.getElementById(steps[currentStep]).style.display = "inline";
            var stepFrame = document.getElementById("stepFrame");
            stepFrame.src = baseHref + "Admin/ProcessUpgradeStep.aspx?action=" + steps[currentStep];
            if (currentStep == 2 || currentStep == 4) {
                // Unzip and ApplyDatabasePatches doesn't stop ASP.NET and can call setApplicationRestarted() on their own. 
                // This is required to make sure that the process waits for the server to finish its work.
                return;
            }
            if (document.getElementById("hidManualRestarts").value == "true") {
                return;
            }
            applicationRestarted = false;
            interval = window.setInterval(function() {
                if (!applicationRestarted)
                    stepFrame.src = baseHref + "Admin/ProcessUpgradeStep.aspx?action=RestartApplication";
            }, 10000);
        }

        function setApplicationRestarted() {
            if (interval)
                window.clearInterval(interval);
            applicationRestarted = true;
            if (document.getElementById("hidManualRestarts").value == "true") {
                document.getElementById("hlManualContinue").style.visibility = "visible";
                return;
            }
            continueProcess();
        }

        function continueProcess() {
            window.setTimeout(function() {
                if (currentStep < 5)
                    executeNextStep();
                else
                    finishUpgrade();
            }, 1000);
        }

        function manualContinueProcess() {
            document.getElementById("hlManualContinue").style.visibility = "hidden";
            if (currentStep < 5)
                window.setTimeout(function() { document.getElementById("hlManualContinue").style.visibility = "visible"; }, 5000);
            continueProcess();
        }


        function finishUpgrade() {
            var hlManualContinue = document.getElementById("hlManualContinue");
            if (hlManualContinue)
                hlManualContinue.style.visibility = "hidden";
            hideSpans();
            document.getElementById("Finished").style.display = "inline";
            //document.getElementById("imgProgress").src = "Admin/Img/icons/accept.png";
            window.setTimeout(function() {
                    window.location.href = window.location.protocol + "//" + window.location.host + "/Admin/Update.aspx?state=upgradecompleted"; 
                }, 500);
        }

        function hideSpans() {
            var spans = document.getElementById("progress").getElementsByTagName("span");
            for (var i = 0; i < spans.length; i++) {
                spans[i].style.display = "none";
            }
        }
        //]]>
    </script>
    <style type="text/css">
        #progress img, #progress span { vertical-align: middle; }
        #progress img { margin-left: 1px; }
        #progress span { padding-left: 3px; font-size: 12px; }
    </style>
</head>
<body onload="">
    <form id="form1" runat="server">
        <input type="hidden" id="hidManualRestarts" runat="server" />
        <div id="publicContainer">
            <div id="ctl00_mainBoxTopOuterContainer">
                <div id="mainBoxTopInnerContainer">
                    <div id="mainBoxTop">
                        <div id="mainBoxTopBg">&nbsp;</div>
                        <div id="mainBoxTopLeftCorner">&nbsp;</div>
                        <div id="mainBoxTopRightCorner">&nbsp;</div>
                    </div>
                </div>
            </div>
            <div id="mainBox">
                <div id="mainBoxLeftBg">&nbsp;</div>
                <div id="mainBoxRightBg">&nbsp;</div>
                <div id="mainBoxContent">
                    <div id="padding">
                        <div class="floatLeft">
                            <img id="imgLogo" runat="server" src="Admin/Img/frediumLogo-dark.png" alt="fredium" />
                        </div>
                        <div class="clearFloats"></div>
                        <div style="margin-top: 10px;">
                            <h2><cms:LocalizedLiteral ID="llHeader" runat="server" /> <asp:Literal ID="litVersion" runat="server" /></h2>
                            <div id="progress">
                                <img id="imgProgress" class="progress" src="Admin/Img/progress.gif" style="margin-right: 10px; vertical-align: middle;" />
                                <span id="RemoveHttpModules">Initializing...</span>
                                <span id="ApplyConfigPatches">Applying config changes...</span>
                                <span id="UnzipUpdatePackage">Unpacking files...</span>
                                <span id="Compiling">Compiling...</span>
                                <span id="ApplyDatabasePatches">Upgrading database...</span>
                                <span id="RestoreHttpModules">Finalizing...</span>
                                <span id="Finished">Finished!</span>
                            </div>
                            <asp:Panel ID="pnlManualRestart" runat="server" style="padding-top: 6px;">
                                <a id="hlManualContinue" href="javascript:void(0);" style="visibility: hidden;" 
                                    onclick="manualContinueProcess();">Wait until the browser has finished loading, restart ASP.NET manually and then click here to proceed</a>
                            </asp:Panel>                            
                            <iframe id="stepFrame" width="400" height="10" frameborder="0" scrolling="no"></iframe>
                        </div>
                    </div>
                </div>
            </div>
            <div id="mainBoxBottom">
                <div id="mainBoxBottomBg">&nbsp;</div>
                <div id="mainBoxBottomLeftCorner">&nbsp;</div>
                <div id="mainBoxBottomRightCorner">&nbsp;</div>
            </div>
        </div>
    </form>
</body>
</html>
